﻿<Window 
    x:Class="BindingSample.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Controls="clr-namespace:System.Windows.Controls;assembly=TreeViewEx" 
    xmlns:Model1="clr-namespace:BindingSample.Model" 
    Title="MainWindow" Height="350" Width="1000">
    <Window.Resources>
        <HierarchicalDataTemplate ItemsSource="{Binding Children}" DataType="{x:Type Model1:Node}">
            <TextBlock>
                <TextBlock.Text>
                    <MultiBinding StringFormat="{}{0} (IsFocused: {1}, IsSelected: {2})">
                        <Binding Path="Name" />
                        <Binding Path="IsFocused" RelativeSource="{RelativeSource AncestorType={x:Type Controls:TreeViewExItem}}"/>
                        <Binding Path="IsSelected" RelativeSource="{RelativeSource AncestorType={x:Type Controls:TreeViewExItem}}"/>
                    </MultiBinding>
                </TextBlock.Text>
            </TextBlock>
        </HierarchicalDataTemplate>
        <Style TargetType="Controls:TreeViewExItem">
            <Setter Property="BorderBrushFocusedSelected" Value="Red"/>
            <Setter Property="BackgroundFocusedSelected" Value="LightSalmon"/>

            <Setter Property="BorderBrushSelected" Value="Blue"/>
            <Setter Property="BackgroundSelected" Value="AliceBlue"/>

            <Setter Property="BorderBrushFocused" Value="Black"/>
            <Setter Property="BackgroundFocused" Value="LightGray"/>

            <Setter Property="BorderBrushHovered" Value="Blue"/>
            <Setter Property="BackgroundHovered" Value="LightBlue"/>

            <Setter Property="BorderBrushInactive" Value="Green"/>
            <Setter Property="BackgroundInactive" Value="LightCyan"/>
        </Style>
    </Window.Resources>
    <DockPanel>
        <StackPanel Orientation="Horizontal" DockPanel.Dock="Bottom">
            <Border BorderThickness="1" BorderBrush="Red">
                <TextBlock Background="LightSalmon" >FocusedSelected</TextBlock>
            </Border>
            <Border BorderThickness="1" BorderBrush="Blue">
                <TextBlock Background="AliceBlue">Selected</TextBlock>
            </Border>
            <Border BorderThickness="1" BorderBrush="Black">
                <TextBlock Background="LightGray" >Focused</TextBlock>
            </Border>
            <Border BorderThickness="1" BorderBrush="Blue">
                <TextBlock Background="LightBlue">Hovered</TextBlock>
            </Border>
            <Border BorderThickness="1" BorderBrush="Green">
                <TextBlock Background="LightCyan">Inactive</TextBlock>
            </Border>
        </StackPanel>
        <StackPanel Orientation="Horizontal" DockPanel.Dock="Bottom">
            <Label Content="SelectedItem: "/>
            <Label Content="{Binding LastSelectedItem.Name, ElementName=leftTree}"/>
        </StackPanel>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Controls:TreeViewEx 
                ItemsSource="{Binding Path=Children}"
                x:Name="leftTree"
                AutomationProperties.AutomationId="leftTree" KeyDown="leftTree_KeyDown" />
            <GridSplitter Width="5" />
            <Controls:TreeViewEx 
                Grid.Column="1"
                ItemsSource="{Binding Path=Children}"
                SelectedItems="{Binding ElementName=leftTree, Path=SelectedItems}"
                AutomationProperties.AutomationId="rightTree"/>
        </Grid>
    </DockPanel>
</Window>
